﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Kiosk.Library;
using System.Windows.Media.Animation;

namespace Kiosk.UserControls
{
    /// <summary>
    /// Interaction logic for EmployeeDirectoryScreen.xaml
    /// </summary>
    public partial class EmployeeDirectoryScreen : BaseKioskControl
    {
        public EmployeeDirectoryScreen()
        {
            InitializeComponent();
        }

        bool lettersLoaded = false;
        private void userControl_Loaded(object sender, RoutedEventArgs e)
        {

            if (!lettersLoaded)
            {
                string myString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

                foreach (char myChar in myString.ToCharArray())
                {
                    LetterButton lb = new LetterButton();
                    lb.Letter = myChar;
                    lb.MouseUp += new MouseButtonEventHandler(letterButton_MouseUp);

                    pnlAlphabet.Children.Add(lb);
                }
                lettersLoaded = true;
            }
        }

        void letterButton_MouseUp(object sender, MouseButtonEventArgs e)
        {
            LetterButton lb = (LetterButton)sender;

            pnlEmployees.Children.Clear();
            foreach (EmployeeInfo anEmployee in EmployeeReadOnlyList.GetAll().Where(emp => emp.LastName.StartsWith(lb.Letter.ToString())).OrderBy(emp => emp.LastName))
            {
                string employeeName = (anEmployee.LastName + ", " + anEmployee.FirstName );
                EmployeeButton eb = new EmployeeButton()
                {
                    DataContext = anEmployee,
                    Height = 100,
                    Width = 300,
                    Margin = new Thickness(5)
                };

                eb.MouseUp += new MouseButtonEventHandler(eb_MouseUp);
                
                pnlEmployees.Children.Add(eb);
            }
        }

        void eb_MouseUp(object sender, MouseButtonEventArgs e)
        {
            EmployeeInfo emp = (EmployeeInfo)((EmployeeButton)sender).DataContext;
            empPres.DataContext = emp;
            Storyboard sb = (Storyboard)this.Resources["showEmp"];
            sb.Begin(this);
            grdSearch.IsHitTestVisible = false;
          
        }

        private void empPres_close(object sender, EventArgs e)
        {
            Storyboard sb = (Storyboard)this.Resources["hideEmp"];
            sb.Begin(this);
            grdSearch.IsHitTestVisible = true;

        }


        private void btnHome_Click(object sender, RoutedEventArgs e)
        {
            OnNavigate(new NavigateEventArgs(new HomeScreen()));
        }

        private void btnScrollLeft_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            scrollViewer.PageLeft(); 
        }

        private void btnScrollRight_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            scrollViewer.PageRight();
        }

   }
}
